public class Main {
    public static void main(String[] args) {
        boolean[][] arr = {
                {false, true, true, true, false, false, false, false, false},
                {false, true, true, true, false, false, true, true, false},
                {false, true, true, true, false, false, true, true, false},
                {false, false, false, false, true, false, true, true, false},
                {true, true, true, false, true, false, false, false, false},
                {true, true, true, false, false, false, false, true, false},
                {false, false, false, false, true, true, true, true, true},
                {true, true, true, false, false, false, false, true, false},
        };
//        boolean[][] arr = {
//                {true, false, false, false, false, true, true, true},
//                {true, false, true, true, true, true, false, false},
//                {false, true, true, true, true, false, true, true},
//                {false, false, false, false, false, false, false, false},
//                {false, true, true, true, true, true, true, true},
//                {false, false, false, false, false, false, false, false},
//                {true, true, false, true, true, true, true, false, false}
//        };
//        boolean[][] arr = {
//                {false, true, false, true},
//                {false, false, false, false},
//        };
//        boolean[][] arr = {
//                {false, false, true, true, false, false},
//                {false, false, true, true, false, false},
//                {true, false, true, true, false, true},
//                {false, false, false, false, false, false},
//                {true, true, true, true, true, true}
//        };
//        boolean[][] arr = {
//                {false, true, true, false},
//                {false, true, true, false},
//        };
        solve(arr);
    }

    static void solve(boolean[][] arr) {
        int height = arr.length, weight = arr[0].length;
        int[][] tver = new int[height][weight];
        int[][] tgor = new int[height][weight];
        int t = 0, t1 = 0, vmax = 0, gmax = 0;
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < weight; j++) {
                t = 0;
                t1 = 0;
                if (arr[i][j]) {
                    t = 1;
                    t += i > 0 ? tver[i - 1][j] : 0;
                    t1 = 1;
                    t1 += j > 0 ? tgor[i][j - 1] : 0;
                }
                if (vmax < t) {
                    vmax = t;
                }
                if (gmax < t1) {
                    gmax = t1;
                }
                tver[i][j] = t;
                tgor[i][j] = t1;
                System.out.print(t + " ");
            }
            System.out.println("");
        }
        System.out.println();
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < weight; j++) {
                System.out.print(tgor[i][j] + " ");
            }
            System.out.println();
        }
        int rx = 0, ry = 0, max = 0, w = 0, h = 0;
        boolean rch = false;
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < weight; j++) {
                if (tver[i][j] > 0) {
                    if (tver[i][j] > 0) {
                        rch = false;
                        if (i == height - 1 && j == weight - 1) {
                            rch = check(tver, tgor, j, i, tver[i][j], tgor[i][j]);
                        } else if (j <= weight - 2 && tgor[i][j+1] != 0 && i <= height - 1) {
                            rch = check(tver, tgor, j, i, tver[i][j+1], tgor[i][j+1]);
                        } else if (i <= height - 2 && tver[i+1][j] == 0 && j <= weight - 1) {
                            rch = check(tver, tgor, j, i, tver[i+1][j], tgor[i+1][j]);
                        }
                        if (i < height - 1 && j < weight - 1)
                            if (tgor[i][j + 1] == 0 && tver[i + 1][j] == 0) {
                                rch = check(tver, tgor, j, i, tver[i][j], tgor[i][j]);
                            }
                        if (rch) {
                            if (tver[i][j] * tgor[i][j] > max && tver[i][j] != tgor[i][j]) {
                                h = tver[i][j];
                                w = tgor[i][j];
                                rx = j - w + 1;
                                ry = i - h + 1;
                                max = tver[i][j] * tgor[i][j];
                            }
                        }
                    }
                }
            }
        }
        System.out.println("\n\n" + ry + " " + rx + " " + h + " " + w);
    }

    static boolean check(int[][] tver, int[][] tgor, int x, int y, int h, int w) {
        boolean tv = true, tg = true;
        int xm = x - w, ym = y - h;
        xm = xm < 0 ? 0 : xm + 1;
        ym = ym < 0 ? 0 : ym + 1;
        for (int i = ym; i <= y; i++) {
            for (int j = xm; j < x; j++) {
                if (!(tver[i][j] == tver[i][j + 1])) {
                    return false;
                }
            }
        }
        for (int i = xm; i <= x; i++) {
            for (int j = ym; j < y; j++) {
                if (!(tgor[j][i] == tgor[j + 1][i])) {
                    return false;
                }
            }
        }
        return true;
    }
}
